// 攻略查询
const express = require('express')
const router = express.Router()
const pool = require('../pool')

// http://127.0.0.1:3000/users/strategy/1
router.get('/', (req, res, next) => {
  var sql = 'select * from qnls_strategy'
  pool.query(sql, (err, result) => {
    console.log(result)
    if (err) {
      return next(err)
    }
    res.send({ code: 200, mag: '查询所有攻略', data: result })
  })
})
router.get('/:sid', (req, res, next) => {
  var obj = req.params
  var sql = 'select * from qnls_strategy where sid = ?'
  pool.query(sql, [obj.sid], (err, result) => {
    if (err) {
      return next(err)
    }
    if (result.length > 0) {
      res.send({ code: 200, mag: '查询到攻略', data: result })
    }
  })
})

module.exports = router
